import http from '@/utils/http'

const BASE_URL = '/report'

export interface ClassStat {
  id: string
  classId: string
  plannedStudentCount: number
  passedStudentCount: number
  renewalStudentCount: number
  cancelStudentCount: number
  retainedStudentCount: number
  totalLessonCount: number
  cancelLessonCount: number

  renewalRate: number
  fullRate: number
  cancelRate: number
  retainedRate: number
  computeDate: string
  confirmed: boolean
}

export interface ClassStatResp extends ClassStat {
  className: string
  leadTeacherName: string
  assistTeacherName: string
  grade: string
}

export interface FinAccountStatResp {
  id: string
  name: string
  account: string
  remark: string
  totalRevenues: number
  totalExpenditures: number
  startTime: string
  endTime: string
  orderCount: number
  refundCount: number
}

// 教师课时
export interface TeacherLessonReportQuery {
  month: string
  teacherType: string
}

export interface TeacherLessonReportResp {
  id: string
  reportDate: string
  leadTeacherId: string
  classId: string
  lessonCount: number
  lessonHourFactor: number
  signInDetails: number[]
  signInCount: number
  fullClassCount: number
  lessonPriceFactor: number
  remark?: string

  className: string
  teacherName: string
}

// 课消
export interface LessonStatReportResp {
  classId: string
  totalLessonPrice: number
  consumedLessonPrice: number
  remainedLessonPrice: number
}
export interface LessonStatListResp {
  studentId: string
  studentName: string
  classId: string
  totalLessonPrice: number
  consumedLessonPrice: number
  remainedLessonPrice: number
}

/** 班级三率统计 */
export function getClassStatList(query: any) {
  return http.get<ClassStatResp[]>(`${BASE_URL}/class/stat`, query)
}
export function getClassStatById(classId: string) {
  return http.get<ClassStat>(`${BASE_URL}/class/stat/${classId}`)
}

/** 财务收支统计 */
export function getFinStat(query: any) {
  return http.get<FinAccountStatResp[]>(`${BASE_URL}/fin/stat`, query)
}

/** 教师课时统计 */
export function getTeacherLessonReport(query: TeacherLessonReportQuery) {
  return http.get<TeacherLessonReportResp[]>(`${BASE_URL}/teacher-lesson/list`, query)
}
export function computeTeacherLessonReport(form: TeacherLessonReportQuery) {
  return http.post(`${BASE_URL}/teacher-lesson/compute`, form)
}

/** 课消统计 */
export function getLessonStatReport(query: any) {
  return http.get<LessonStatReportResp[]>(`${BASE_URL}/lesson/stat`, query)
}
export function getLessonStatList(query: any) {
  return http.get<LessonStatListResp[]>(`${BASE_URL}/lesson/list`, query)
}
